#ifndef _INTERPOLATE_H_
#define _INTERPOLATE_H_


namespace math
{

/***
 *	@brief: Templetized function for interpolating between two values given a float Key
 *
 */
template <class T> 
class Interpolate
{
public:
/***
 *	@brief: not setup by default.. needs to use Set before valid!
 */
	Interpolate() 
	{
		m_FromKey = m_ToKey = 0.0f;
	}
/***
 *	@brief: Setup interpolationg for a range (FromKey..ToKey)
 */
	Interpolate(T FromVal, T ToVal, float FromKey, float ToKey)
	{
		Set(FromVal, ToVal, FromKey, ToKey);
	}
/***
 *	@brief: Setup interpolationg for a range (0..KeyRange)
 */
	Interpolate(T FromVal, T ToVal, float KeyRange = 1.0f)
	{
		Set(FromVal, ToVal, 0, KeyRange);
	}

/***
 *	@brief: Get the interpolated value at some point Key in (FromKey..ToKey).\n
			Uses a straight lerp, nothing fancy
	@returns: the value at point Key
 */
	T		GetValue(float Key)
	{
		float BaseKey = (Key - m_FromKey);
		float t = BaseKey / (m_ToKey - m_FromKey);
		if (t > 1.0f) t = 1.0f;	// cap it
		if (t < 0.0f) t = 0.0f;

		return m_FromVal + (m_Range * t);
	}

	/***
	*	@brief: Setup interpolationg for a range (FromKey..ToKey)
	*/
	void	Set(T FromVal, T ToVal, float FromKey, float ToKey)
	{
		m_FromVal = FromVal;
		m_ToVal   = ToVal;
		m_Range   = m_ToVal - m_FromVal;
		m_FromKey = FromKey;
		m_ToKey   = ToKey;
	}

protected:
	T		m_FromVal, m_ToVal, m_Range;
	float	m_FromKey, m_ToKey;

};


}

#endif // _INTERPOLATE_H_